﻿using DevExpress.XtraEditors;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.有赞.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.有赞.有赞商品
{
    public partial class Form有赞Spu及Sku一览 : DevExpress.XtraEditors.XtraForm
    {
        public Form有赞Spu及Sku一览()
        {
            InitializeComponent();
            this.刷新();
        }

        private void 刷新()
        {
            List<YouzanSpuCostStockDTO> youzanSpuCostStockDTOs = 有赞商品Service.getYouzanSpuCostStockAll();
            List<YouzanSpuCostStockVO> youzanSpuCostStockVOs = new List<YouzanSpuCostStockVO>();
            foreach (YouzanSpuCostStockDTO item in youzanSpuCostStockDTOs)
            {
                youzanSpuCostStockVOs.Add(new YouzanSpuCostStockVO(item));
            }
            this.gridControlSpuSku一览.DataSource = youzanSpuCostStockVOs;
            this.advBandedGridView1.RefreshData();
            this.gridViewSku库存.RefreshData();
        }

        private void simpleButton刷新_Click(object sender, EventArgs e)
        {
            this.刷新();
        }
    }

    public class YouzanSpuCostStockVO
    {
        /**
         * spu数据
         */
        public int itemId { get; set; }  //     商品Id
        public String detailUrl { get; set; }    //  商品详情链接
        public DateTime createdTime { get; set; }    //  创建时间
        public int itemType { get; set; }    //  商品类型
        public String title { get; set; }    // 商品名称
        public String shareTitle { get; set; }    //  商品名称
        public String origin { get; set; }    //  划线价
        public Double price { get; set; }    // 商品价格
        public int quantity { get; set; }    // 总库存
        public String groupAlias { get; set; }
        public String groupId { get; set; }
        public String groupName { get; set; }
        public String imageUrl { get; set; }
        public Image image { get; set; }
        //  价格体系
        public String styleCode { get; set; }
        public String styleName { get; set; }   //  款名
        public String materialCode { get; set; }
        public String materialName { get; set; }    //  面料名
        public String composition { get; set; } //  成分
        public String refBarcode { get; set; } //   参考码
        public Double salePrice { get; set; }   //  零售价，吊牌价
        public Double onlineSalePrice { get; set; } //  电商零售价
        public DateTime createDate { get; set; }
        /**
         * sku规格及库存数
         */
        public List<YouzanSkuStockDto> youzanSkuStockDtos { get; set; }

        public YouzanSpuCostStockVO(YouzanSpuCostStockDTO youzanSpuCostStockDTO)
        {
            this.itemId = youzanSpuCostStockDTO.itemId;
            this.detailUrl = youzanSpuCostStockDTO.detailUrl;
            this.createdTime = youzanSpuCostStockDTO.createdTime;
            this.itemType = youzanSpuCostStockDTO.itemType;
            this.title = youzanSpuCostStockDTO.title;
            this.shareTitle = youzanSpuCostStockDTO.shareTitle;
            this.origin = youzanSpuCostStockDTO.origin;
            this.price = youzanSpuCostStockDTO.price;
            this.quantity = youzanSpuCostStockDTO.quantity;
            this.groupAlias = youzanSpuCostStockDTO.groupAlias;
            this.groupId = youzanSpuCostStockDTO.groupId;
            this.groupName = youzanSpuCostStockDTO.groupName;
            this.imageUrl = youzanSpuCostStockDTO.imageUrl;
            try
            {
                this.image = FileService.GetImageByUrl(youzanSpuCostStockDTO.imageUrl);
            }
            catch { }
            this.styleCode = youzanSpuCostStockDTO.styleCode;
            this.styleName = youzanSpuCostStockDTO.styleName;
            this.materialCode = youzanSpuCostStockDTO.materialCode;
            this.materialName = youzanSpuCostStockDTO.materialName;
            this.composition = youzanSpuCostStockDTO.composition;
            this.refBarcode = youzanSpuCostStockDTO.refBarcode;
            this.salePrice = youzanSpuCostStockDTO.salePrice;
            this.onlineSalePrice = youzanSpuCostStockDTO.onlineSalePrice;
            this.createDate = youzanSpuCostStockDTO.createDate;
            this.youzanSkuStockDtos = youzanSpuCostStockDTO.youzanSkuStockDtos;
        }
    }
}